import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class homeWork {
    public static void main(String[] args) {
        List<Integer> zhangHuJinEr = new ArrayList<>();
        List<Integer> shouRuJinEr = new ArrayList<>();
        List<String> shuoMing = new ArrayList<>();
        Integer money = 0;
        int mini = 100;
        while (mini != -1000) {
            sayInformation();
            try {
                Scanner scanner = new Scanner(System.in);
                int number = scanner.nextInt();
                if(number<0||number>4){
                    System.out.println("请输入1~4");
                    continue;
                }
                switch (number) {
                    case 1:
                        shouRuMingXi(zhangHuJinEr, shouRuJinEr, shuoMing);
                        end();
                        break;
                    case 2:
                        Scanner scanner1 = new Scanner(System.in);
                        int changeMoney1 = scanner.nextInt();
                        money = getMoney(money, changeMoney1);
                        Scanner s1 = new Scanner(System.in);
                        String name1=s1.nextLine();
                        zhangHuJinEr.add(money);
                        shouRuJinEr.add(changeMoney1);
                        shuoMing.add(name1);
                           end();
                        break;
                    case 3:
                        Scanner scanner2 = new Scanner(System.in);
                        int changeMoney2 = scanner2.nextInt();
                        money = pullMoney(money, changeMoney2);
                        if (money==-1){
                            System.out.println("余额不足");
                            break;
                        }
                        Scanner s2 = new Scanner(System.in);
                        String name2=s2.nextLine();
                        zhangHuJinEr.add(money);
                        shouRuJinEr.add(-changeMoney2);
                        shuoMing.add(name2);
                        end();
                        break;
                    case 4:
                        mini=-1000;
                        end();
                        break;

                }
            } catch (Exception e) {
                System.out.println("请输入合法数字");
            }

        }

    }

    public static void sayInformation() {
        System.out.println("--------------家庭收入记账软件-----------------");
        System.out.println("1、收入明细");
        System.out.println("2、登记收入");
        System.out.println("3、登记收出");
        System.out.println("4、退出");
        System.out.print("请选择：（1~4）");
    }

    public static void end() {
        System.out.println("-------------操作完成------------------");
    }

    public static void shouRuMingXi(List<Integer> zhangHuJinEr,
                                    List<Integer> shouRuJinEr,
                                    List<String> shuoMing) {
        System.out.println("账户金额      收支金额      说明");
        for (int i = 0; i < zhangHuJinEr.size(); i++) {
            System.out.print(zhangHuJinEr.get(i));
            System.out.print("        " + shouRuJinEr.get(i));
            System.out.println("        " + shuoMing.get(i));
        }
    }

    public static Integer pullMoney(Integer money,
                                    Integer changeMoney) {
        if (money - changeMoney > 0) {
            return money - changeMoney;
        }
        return -1;
    }

    public static Integer getMoney(Integer money,
                                   Integer changeMoney) {
        return money + changeMoney;
    }

    public static Integer endWork() {
        return -1000;
    }
}
